<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace app\dao\setting;

use app\dao\BaseDao;
use app\model\setting\SystemMenu;

class SystemMenuDao extends BaseDao
{
    /**
     * 设置模型
     * @return string
     */
    protected function setModel(): string
    {
        return SystemMenu::class;
    }

    /**
     * 根据权限获取菜单
     * @param array $where
     * @param array|null $field
     * @return mixed
     */
    public function getMenuByRole(array $where = [], ?array $field = []): mixed
    {
        if (!$field) {
            $field = ['*'];
        }
        return $this->search($where)->field($field)->order('sort DESC, id DESC')->select()->toArray();
    }

    /**
     * 查询菜单
     * @param array $where
     * @return mixed
     */
    public function findSystemMenu(array $where = []): mixed
    {
        return $this->search($where)->find();
    }
}
